const App = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isLoading: true,
    dataType: 1,
    page: 1,
    no_more: false,
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let team = this.data.list;
    // 获取我的团队列表
    if(!team){
      this.getTeamList();
    }
  },

  /**
   * 获取我的团队列表
   */
  getTeamList: function(isNextPage, page) {
    let _this = this;
    //console.log(_this.data.rand);
    App._get('user.follow/lists', {
      page: page || 1,
    }, function(result) {
      console.log(result);
      // 创建页面数据
      let tang = _this.createData(result.data, isNextPage);
      _this.setData(tang);
      _this.setData({
        number: result.data.number
      });
    });
  },

  /**
   * 创建页面数据
   */
  createData: function(data, isNextPage) {
    data['isLoading'] = false;
    // 列表数据
    let dataList = this.data.list;
    if (isNextPage == true && (typeof dataList !== 'undefined')) {
      data.list.data = dataList.data.concat(data.list.data);
    }
    // 设置swiper的高度
    this.setSwiperHeight();
    return data;
  },

  /**
   * 设置swiper的高度
   */
  setSwiperHeight: function(isTap) {
    // 获取系统信息(拿到屏幕宽度)
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = isTap ? Math.floor(rpx * 82) : 0, // tap高度
      //peopleHeight = Math.floor(rpx * 65), // people高度
      tang = Math.floor(rpx * 180), 
      swiperHeight = systemInfo.windowHeight - tapHeight -tang; // swiper高度
    
    this.setData({
      swiperHeight
    });
  },

  /**
   * 点击加载数据
   */
  triggerDownLoad: function () {
    // 已经是最后一页
    if (this.data.page >= this.data.list.last_page) {
      this.setData({
        no_more: true
      });
      return false;
    }
    this.getTeamList(true, ++this.data.page);
  },


  //关注
  unguanzhu:function(e){
    let _this = this;
    let to_user_id = e.currentTarget.dataset.user_id;
    wx.showModal({
      title: '提示',
      content: '您确定要取消关注吗？',
      success(res) {
        if (res.confirm) {
          App._get('user.follow/unfollow', {
            to_user_id: to_user_id
          }, function (result) {
            //App.showSuccess(result.msg);
            _this.getTeamList();
          });
        } else if (res.cancel) {
          //console.log('用户点击取消')
        }
      }
    })
  },

  //跳转 用户详情页
  goToDetail:function(e){
    let user_id = e.currentTarget.dataset.user_id;
    wx.navigateTo({
      url: '../../social/detail?user_id=' + user_id
    })
  },

})